package TCP.Demo1;

import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.net.Socket;


/**
 * @author 君未洋
 */
@SuppressWarnings("ALL")
public class TCPClient {
    public static void main(String[] args) throws IOException {
        //客户端
        Socket socket = new Socket("127.0.0.1", 8888);
        //创建对应的socket对象
        OutputStream os = socket.getOutputStream();
        //获取流对象
        os.write("你好服务器".getBytes());
        //给服务器发送数据

        InputStream is = socket.getInputStream();
        //获取输出流对象
        byte[] bytes = new byte[1024];
        int len = is.read(bytes);
        System.out.println(new String(bytes, 0, len));
        //打印服务器发送的数据

        //施放客户端Scoket对象
        socket.close();
    }
}
